<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 任务模型
 *
 * Class Task
 * @property $id
 * @property $categorys
 * @package App\Models
 */
class Task extends Model
{
    use SoftDeletes;

	/**
	 * 定义可填充字段
	 *
	 * @var array
	 * Date: 2018/2/2
	 * @author George
	 */
    protected $fillable = [
        'name',
        'type',
        'required',
        'photo',
        'params',
    ];

	/**
	 * 定义字段数据类型
	 *
	 * @var array
	 * Date: 2018/2/2
	 * @author George
	 */
	protected $casts = [
		'params' => 'json'
	];

    /**
     * 获取任务的分类
     *
     * Data: 2018/1/30
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function categorys(){
        return $this->belongsToMany(Category::class, 'category_task_pivot', 'task_id', 'category_id');
    }


}
